<?php

namespace App\Http\Requests\Business;

use Illuminate\Foundation\Http\FormRequest;

class ExternalOrderDetailsRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'year' => 'required|numeric',
            'payer_code' => 'required|exists:payer,code',
            'material_code' => 'required|exists:material,material',
            'category_contract_id' => 'exists:category_contract,id',
            'quantity' => 'required|integer',
            'amount' => 'required|numeric',

        ];
        switch (request()->method) {
            case 'POST':
                break;
            case 'PUT':
                break;
            default:
                break;
        }

        return $rules;
    }

    public function messages()
    {
        return [
            'year.required' => '请输入年份！',
            'year.numeric' => '年份格式不正确！',
            'payer_code.required' => '请输入客户代码！',
            'payer_code.exists' => '客户代码不存在！',
            'material_code.required' => '请输入物料编码！',
            'material_code.exists' => '物料编码不存在！',
            'category_contract_id.exists' => '品类不存在！',
            'quantity.required' => '请输入数量！',
            'quantity.integer' => '数量必须为整数！',
            'amount.required' => '请输入金额！',
            'amount.numeric' => '金额为数字格式！',
        ];
    }
}
